﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using System.Data.EntityClient;

using FinalProject.DAL.Model;

namespace FinalProject.DAL.Mapping
{
    public class InvoiceModelContext : ObjectContext
    {
        #region Constructors

        /// <summary>
        /// Initializes a new InvoiceModelContainer object using the connection string found in the 'InvoiceModelContainer' section of the application configuration file.
        /// </summary>
        public InvoiceModelContext()
            : base("name=InvoiceModelContext", "InvoiceModelContext")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }

        /// <summary>
        /// Initialize a new InvoiceModelContainer object.
        /// </summary>
        public InvoiceModelContext(string connectionString)
            : base(connectionString, "InvoiceModelContext")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }

        /// <summary>
        /// Initialize a new InvoiceModelContainer object.
        /// </summary>
        public InvoiceModelContext(EntityConnection connection)
            : base(connection, "InvoiceModelContext")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }

        #endregion

        #region Partial Methods

        public delegate void ChangedContextHandler(object sender, EventArgs e);
        public event ChangedContextHandler ContextCreated;
        protected void OnContextCreated()
        {
            if (ContextCreated != null)
                ContextCreated(this, EventArgs.Empty);
        }

        #endregion

        #region ObjectSet Properties

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<OrderDocument> OrderDocuments
        {
            get
            {
                if ((_OrderDocuments == null))
                {
                    _OrderDocuments = base.CreateObjectSet<OrderDocument>("OrderDocuments");
                }
                return _OrderDocuments;
            }
        }
        private ObjectSet<OrderDocument> _OrderDocuments;

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<DeliveryDocument> DeliveryDocuments
        {
            get
            {
                if ((_DeliveryDocuments == null))
                {
                    _DeliveryDocuments = base.CreateObjectSet<DeliveryDocument>("DeliveryDocuments");
                }
                return _DeliveryDocuments;
            }
        }
        private ObjectSet<DeliveryDocument> _DeliveryDocuments;

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<InvoiceDocument> InvoiceDocuments
        {
            get
            {
                if ((_InvoiceDocuments == null))
                {
                    _InvoiceDocuments = base.CreateObjectSet<InvoiceDocument>("InvoiceDocuments");
                }
                return _InvoiceDocuments;
            }
        }
        private ObjectSet<InvoiceDocument> _InvoiceDocuments;

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<DocumentRow> DocumentRows
        {
            get
            {
                if ((_DocumentRows == null))
                {
                    _DocumentRows = base.CreateObjectSet<DocumentRow>("DocumentRows");
                }
                return _DocumentRows;
            }
        }
        private ObjectSet<DocumentRow> _DocumentRows;

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<Item> Items
        {
            get
            {
                if ((_Items == null))
                {
                    _Items = base.CreateObjectSet<Item>("Items");
                }
                return _Items;
            }
        }
        private ObjectSet<Item> _Items;

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<Warehouse> Warehouses
        {
            get
            {
                if ((_Warehouses == null))
                {
                    _Warehouses = base.CreateObjectSet<Warehouse>("Warehouses");
                }
                return _Warehouses;
            }
        }
        private ObjectSet<Warehouse> _Warehouses;

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<Journal> Journals
        {
            get
            {
                if ((_Journals == null))
                {
                    _Journals = base.CreateObjectSet<Journal>("Journals");
                }
                return _Journals;
            }
        }
        private ObjectSet<Journal> _Journals;

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<JournalType> JournalTypes
        {
            get
            {
                if ((_JournalTypes == null))
                {
                    _JournalTypes = base.CreateObjectSet<JournalType>("JournalTypes");
                }
                return _JournalTypes;
            }
        }
        private ObjectSet<JournalType> _JournalTypes;

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<Customer> Customers
        {
            get
            {
                if ((_Customers == null))
                {
                    _Customers = base.CreateObjectSet<Customer>("Customers");
                }
                return _Customers;
            }
        }
        private ObjectSet<Customer> _Customers;

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<Voucher> Vouchers
        {
            get
            {
                if ((_Vouchers == null))
                {
                    _Vouchers = base.CreateObjectSet<Voucher>("Vouchers");
                }
                return _Vouchers;
            }
        }
        private ObjectSet<Voucher> _Vouchers;

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<CollectionMoney> CollectionMoneys
        {
            get
            {
                if ((_CollectionMoneys == null))
                {
                    _CollectionMoneys = base.CreateObjectSet<CollectionMoney>("CollectionMoneys");
                }
                return _CollectionMoneys;
            }
        }
        private ObjectSet<CollectionMoney> _CollectionMoneys;

        private ObjectSet<CustomerBalance> _customerBalances;
        public ObjectSet<CustomerBalance> CustomerBalances
        {
            get
            {
                if (_customerBalances == null)
                {
                    _customerBalances = base.CreateObjectSet<CustomerBalance>("CustomerBalances");
                }
                return _customerBalances;
            }
        }

        #endregion

        #region AddTo Methods

        /// <summary>
        /// Deprecated Method for adding a new object to the OrderDocuments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToOrderDocuments(OrderDocument orderDocument)
        {
            base.AddObject("OrderDocuments", orderDocument);
        }

        /// <summary>
        /// Deprecated Method for adding a new object to the DeliveryDocuments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToDeliveryDocuments(DeliveryDocument deliveryDocument)
        {
            base.AddObject("DeliveryDocuments", deliveryDocument);
        }

        /// <summary>
        /// Deprecated Method for adding a new object to the InvoiceDocuments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToInvoiceDocuments(InvoiceDocument invoiceDocument)
        {
            base.AddObject("InvoiceDocuments", invoiceDocument);
        }

        /// <summary>
        /// Deprecated Method for adding a new object to the DocumentRows EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToDocumentRows(DocumentRow documentRow)
        {
            base.AddObject("DocumentRows", documentRow);
        }

        /// <summary>
        /// Deprecated Method for adding a new object to the Items EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToItems(Item item)
        {
            base.AddObject("Items", item);
        }

        /// <summary>
        /// Deprecated Method for adding a new object to the Warehouses EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToWarehouses(Warehouse warehouse)
        {
            base.AddObject("Warehouses", warehouse);
        }

        /// <summary>
        /// Deprecated Method for adding a new object to the Journals EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToJournals(Journal journal)
        {
            base.AddObject("Journals", journal);
        }

        /// <summary>
        /// Deprecated Method for adding a new object to the JournalTypes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToJournalTypes(JournalType journalType)
        {
            base.AddObject("JournalTypes", journalType);
        }

        /// <summary>
        /// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToCustomers(Customer customer)
        {
            base.AddObject("Customers", customer);
        }

        /// <summary>
        /// Deprecated Method for adding a new object to the Vouchers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToVouchers(Voucher voucher)
        {
            base.AddObject("Vouchers", voucher);
        }

        /// <summary>
        /// Deprecated Method for adding a new object to the CollectionMoneys EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToCollectionMoneys(CollectionMoney collectionMoney)
        {
            base.AddObject("CollectionMoneys", collectionMoney);
        }

        #endregion

    }
}
